package com.cuijq.dubbo.core.config;

import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
import com.alibaba.cloud.nacos.registry.NacosRegistration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Configurable
@Slf4j
public class NacosRegistrationPort implements ApplicationRunner {
    @Autowired
    private NacosRegistration registration;

    @Autowired
    private NacosAutoServiceRegistration nacosAutoServiceRegistration;

    @Value("${netty.port}")
    Integer port;

    @Override
    public void run(ApplicationArguments args)   {
        if (registration != null && port != null) {
            Integer nettyPort = port;
            registration.setPort(nettyPort);
            nacosAutoServiceRegistration.start();
        }
    }
}
